/*
 * @Descripttion: 自定义ajax请求
 * @version: 1.0.0
 * @Author: 某人
 * @Date: 2021-05-21 11:02:02
 */

const getJSON = function(url) {
  return new Promise((resolve, reject) => {
    // 创建HTTP请求
    const xhr = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Mricosoft.XMLHttp')
    // 设置请求数据
    xhr.open('GET', url, false)
    // 设置响应头
    xhr.setRequestHeader('Accept', 'application/json')
    // 响应方法回调
    xhr.onreadystatechange = function () {
      if (xhr.readyState !== 4) return
      if (xhr.status === 200 || xhr.status === 304) {
        resolve(xhr.responseText)
      } else {
        reject(new Error(xhr.responseText))
      }
    }
    xhr.send()
  })
}
